/**
 * 
  * @author juan
 *
 */

package Server;
import java.util.Calendar;
import java.util.Map;
import java.io.*;

/**
 * @author David
 * @version $Revision: 1.0 $
 */
public class Admin extends User{
	
	/**
	 * Field fout.
	 */
	private FileOutputStream fout;

	/**
	 * Field cal.
	 */
	private final Calendar cal = Calendar.getInstance();
	
	/**
	 * Constructor for Admin.
	 */
	protected Admin(String n, String p){
		super(n, p);
		try{
			final File logFile = new File("Log.txt");
			if (!(logFile.exists())){
				try{
					logFile.createNewFile();
					//log("Log Created");
				}
				catch(IOException e1){
					System.out.println("IOException");
				}
			}
			else{
				System.out.println("Else");
			}
			fout = new FileOutputStream(logFile);
		}
		catch(FileNotFoundException e){
			System.out.println("Error: File Not Found");
		}
	}
	
	/**
	 * Method toString.
	
	 * @return String */
	public String toString(){
		final String str = "";
		return str;
	}
	
	/**
	 * Method log.
	 * @param s String
	 */
	public void log(String s){
		//appends string with timestamp
		final String str = s + " " + cal.getTime();
		try{
			fout.write(str.getBytes());
			fout.flush();
		}catch(IOException e2){
			System.out.println("IOException on log");
		}
	}
	
	private void test(){
		System.out.println("testing...");
	}

	/**
	 * Field userMap.
	 */
	private Map<String, User> userMap; 
	
	/*
	private Admin(){
		userMap = new HashMap<String,User> ();
	}
	*/
	/**
	 * Method addUser.
	 * @param u User
	 */
	public void addUser(User u){
		userMap.put(u.getName(), u);
	}

	/**
	 * Method findUser.
	 * @param name String
	
	 * @return User */
	public User findUser(String name) {
		return userMap.get(name);
		
		}

	public static void main(String [] args){
		Admin admin = new Admin("admin", "password");
		admin.test();
	}
}